﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Consulta.Core;

public partial class Pages_SaldoAlmacen : System.Web.UI.Page
{
    double totEntradas = 0;
    double totSalidas = 0;
    double totSalIni = 0;
    double totSalAct = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (User.IsInRole(@"COSTARICA\CR_Intranet_Inventarios.R") || User.IsInRole(@"GRUPOBANACOL\CR_Intranet_Inventarios.R"))
            {
                Label lblTituloMaster = new Label();
                lblTituloMaster = (Label)this.Form.Parent.FindControl("lblTitulo");
                lblTituloMaster.Text = "Intranet-Consulta de Inventarios Almacenes";
                if (Page.Request.QueryString.Count > 0)
                {
                    lblCodigo.Text = Page.Request.QueryString["Codigo"];
                    lblNombre.Text = "Existencias del producto : " + " (" + lblCodigo.Text + ")" +
                                    Page.Request.QueryString["Nombre"] +
                                    " (" + Page.Request.QueryString["Unidad"] + ")";
                }
            }
            else
            {
                Response.Redirect("~/Pages/PaginaMensaje.aspx?Msj=Lo sentimos. Usted no tiene autorización para ingresar a esta página.");
            }
        }
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.DataItem != null)
            {
                totEntradas += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "Entradas"));
                totSalidas += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "Salidas"));
                totSalIni += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "SaldoInicial"));
                totSalAct += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "SaldoActual"));
            }
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[4].Text = "Totales : ";
            e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells[5].Text = totSalIni.ToString("n0");
            e.Row.Cells[5].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells[6].Text = totEntradas.ToString("n0");
            e.Row.Cells[6].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells[7].Text = totSalidas.ToString("n0");
            e.Row.Cells[7].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Cells[8].Text = totSalAct.ToString("n0");
            e.Row.Cells[8].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Font.Bold = true;
        }
    }
}
